#include "editor_widget.h"
#include "ui_editor_widget.h"

editor_widget::editor_widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::editor_widget)
{
    ui->setupUi(this);

}

editor_widget::~editor_widget()
{
    delete ui;
}

void editor_widget::setConnect(AudioThread *at, WaveForm *wf)
{
            QPixmap lab(QCoreApplication::applicationDirPath() + "/icon/volume.png");
            QIcon labIcon(lab);
            ui->label_volume->setText("");
            ui->label_volume->setPixmap(lab);
            QCheckBox* check = ui->checkBox;
            check->setToolTip("On/Off");
            connect(check, SIGNAL(clicked(bool)), at, SLOT(check(bool)));

            //
            QPushButton* but = ui->pushButton_delete;
            connect(but, SIGNAL(clicked()), at, SLOT(del()));
            QPixmap pixmap(QCoreApplication::applicationDirPath() + "/icon/delete.png");
            QIcon ButtonIcon(pixmap);
            but->setIcon(ButtonIcon);
            //but->setIconSize(pixmap.rect().size());

            //
            QSlider* volume = ui->horizontalSlider_volume;
            connect(volume, SIGNAL(sliderMoved(int)), at, SLOT(volume(int)));

            //
            QSlider* leftRight = ui->horizontalSlider_panoram;
            connect(leftRight, SIGNAL(sliderMoved(int)), at, SLOT(leftRight(int)));

            //
            QPushButton* delFX = ui->pushButton_effect;
            connect(delFX, SIGNAL(clicked()), at, SLOT(del_effects()));
            connect(delFX, SIGNAL(clicked()), wf, SLOT(delEffects()));
            QPixmap eff(QCoreApplication::applicationDirPath() + "/icon/effect_del.png");
            QIcon ButtonIcon2(eff);
            delFX->setIcon(ButtonIcon2);
            delFX->setIconSize(QSize(32,32));

            QPixmap lab3(QCoreApplication::applicationDirPath() + "/icon/undo.png");
            ui->label_refresh->setText("");
            ui->label_refresh->setPixmap(lab3);
            ui->label_refresh->installEventFilter(this);

            this->at = at;
}

bool editor_widget::eventFilter(QObject *obj, QEvent *event)
{

    if(event->type() == QEvent::MouseButtonPress)
    {
        at->addAttribute(BASS_ATTRIB_TEMPO, 0);
        at->addAttribute(BASS_ATTRIB_TEMPO_PITCH, 0);
        at->addAttribute(BASS_ATTRIB_FREQ, 44100);

        return true;
    }
    else
        return QObject::eventFilter(obj, event);
}


QCheckBox *editor_widget::getCheck()
{
    return ui->checkBox;
}

QSlider *editor_widget::getVolume()
{
    return ui->horizontalSlider_volume;
}

QSlider *editor_widget::getChannel()
{
    return ui->horizontalSlider_panoram;
}

void editor_widget::disconnectWidgets()
{
    ui->checkBox->disconnect();
    ui->horizontalSlider_panoram->disconnect();
    ui->horizontalSlider_volume->disconnect();
    ui->pushButton_delete->disconnect();
    ui->pushButton_effect->disconnect();
}
